﻿namespace DreamBuilder.Common
{
    using System;
    using System.Data;
    using System.Globalization;
    using System.Web;
    using System.Xml;

    public sealed class CultureList
    {
        public static DataTable GetCultureList()
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/Config/Culture.xml"));
            XmlNodeList list = document.SelectNodes("SupportCultureList/Culture");
            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("CultureName", Type.GetType("System.String")));
            table.Columns.Add(new DataColumn("DisplayName", Type.GetType("System.String")));
            string name = "";
            for (int i = 0; i < list.Count; i++)
            {
                DataRow row = table.NewRow();
                name = list.Item(i).InnerText;
                CultureInfo info = CultureInfo.CreateSpecificCulture(name);
                row[0] = name;
                if (name == "ru-RU")
                {
                    row[1] = "Русский язык";
                }
                else
                {
                    row[1] = info.NativeName;
                }
                table.Rows.Add(row);
            }
            return table;
        }
    }
}

